﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAO;
namespace BUS
{
    public class ChuyenBayBUS
    {
      public DataTable TimKiemChuyenBay(string maSanBayDi, string maSanBayDen, string thoiGianDi)
     {
         ChuyenBayDAO dao = new ChuyenBayDAO();
         
         string fthoiGianDi = string.Format("{0:yyyy-MM-dd}",Convert.ToDateTime(thoiGianDi));
         return dao.TimKiemChuyenBay(maSanBayDi, maSanBayDen, fthoiGianDi);
     }
      public DataTable TimKiemChuyenBay(string maSanBayDi, string maSanBayDen, string thoiGianDi,string proc)
      {
          ChuyenBayDAO dao = new ChuyenBayDAO();

          string fthoiGianDi = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(thoiGianDi));
          return dao.TimKiemChuyenBay(maSanBayDi, maSanBayDen, fthoiGianDi,proc);
      }
      public DataTable TimKiemChuyenBayTheoTieuChi(string maSanBay ,string thoiGianDi,string proc)
      {
          ChuyenBayDAO dao = new ChuyenBayDAO();

          string fthoiGianDi = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(thoiGianDi));
          return dao.TimKiemChuyenBayTheoTieuChi(maSanBay,fthoiGianDi,proc);
      }
      public DataTable layThongTinVeDoiLichTrinh(string maKhachHang, string ngayDat)
      {
          ChuyenBayDAO dao = new ChuyenBayDAO();

          string fngayDat = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(ngayDat));
          return dao.layThongTinVeDoiLichTrinh(maKhachHang, fngayDat);
      }
      public DataTable layThongTinChuyenBay(string ngayDat)
      {

          ChuyenBayDAO dao = new ChuyenBayDAO();

          string fngayDat = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(ngayDat));
          return dao.layThongTinChuyenBay(fngayDat);
      }
      public DataTable layThongTinChuyenBay()
      {

          ChuyenBayDAO dao = new ChuyenBayDAO();

          return dao.layThongTinChuyenBay();
      }
      public void themChuyenBayMoi(string maChangBay,string soHieuMayBay,string ngayDi,string ngayDen,string gioDi,string gioDen,float tongGioBay,float giaVeHangThuongGia, float giaVeHangPhoThong, float giaVeHangTietKiem,float chiPhiDichVuDuKien)
      {
          string maChuyenBay = "";
         
          ChuyenBayDAO dao = new ChuyenBayDAO();
          MayBayDAO mb = new MayBayDAO();
          ChangBayChuyenBayDAO cbcb = new ChangBayChuyenBayDAO();
          ChuyenBayDAO cb1 = new ChuyenBayDAO();
          BangGiaVeDAO bgv = new BangGiaVeDAO();
          ChangBayDAO cb = new ChangBayDAO();
          int count = dao.demSoChuyenBay();
          maChuyenBay = "CB0" + (count + 1).ToString();
          int maMayBay = mb.layIDMayBay(soHieuMayBay);
          int soChoHang1 = int.Parse(mb.laySoCho(soHieuMayBay).Rows[0]["ThuongNhan"].ToString());
          int soChoHang2 = int.Parse(mb.laySoCho(soHieuMayBay).Rows[0]["PhoThong"].ToString());
          int soChoHang3 = int.Parse(mb.laySoCho(soHieuMayBay).Rows[0]["TietKiem"].ToString());
          string viTri = cb.laySanBayDenCuaChangBay(int.Parse(maChangBay));
          string ngayDi1 =string.Format("{0:yyyy-MM-dd}",DateTime.Parse(ngayDi).AddDays(-1));
          ngayDi = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(ngayDi));
          ngayDen =  string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(ngayDen));
          int ID = mb.layIDLichSuBay(ngayDi1, int.Parse(maChangBay));
          cb1.themMoiChuyenbay(maChuyenBay, maMayBay,chiPhiDichVuDuKien);
          mb.themLichSuBay(soHieuMayBay, ngayDi,ngayDen, "Đang Bay", 1, viTri);
          mb.capNhatLichSuBay(ID);
          bgv.themBangGiaVe(maChuyenBay, soChoHang1, soChoHang2, soChoHang3, giaVeHangThuongGia, giaVeHangPhoThong, giaVeHangTietKiem);
          cbcb.themChangBayChuyenBay(maChangBay, maChuyenBay, ngayDi, ngayDen, gioDi, gioDen, tongGioBay);

      }
      public DataTable layThongTinChuyenBayChangBay(int maChangBay, string ngayDi)
      {
          ChuyenBayDAO dao = new ChuyenBayDAO();

          return dao.layThongTinChuyenBayChangBay(maChangBay, ngayDi);
      }
      public void capNhatChiPhiChuyenBay(string maChuyenBay, float nhienLieu, float chiPhi)
      {
          ChuyenBayDAO dao = new ChuyenBayDAO();
          dao.capNhatChiPhiChuyenBay(maChuyenBay, nhienLieu, chiPhi);

      }
    }
    
}
